﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using BusinessObjects;
using DataAccess;

namespace QuanLyHopDong
{
    public partial class HinhThucHopDongDetailView : Form
    {
        public event EventHandler SaveChanged;
        public event EventHandler DeleteChanged;

        private BindingList<HinhThucHopDong> bindingListHinhThucHopDong;
        private HinhThucHopDong _hinhThucHopDong;

        public HinhThucHopDongDetailView()
        {
            InitializeComponent();
        }
        public HinhThucHopDongDetailView(HinhThucHopDong hinhThucHopDong)
        {
            InitializeComponent();

            _hinhThucHopDong = hinhThucHopDong;
            bindingListHinhThucHopDong = new BindingList<HinhThucHopDong>();
            bindingListHinhThucHopDong.Add(_hinhThucHopDong);

            bindingSourceHinhThucHopDong.DataSource = bindingListHinhThucHopDong;
            layoutControl1.Refresh();
        }

        private void btnLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Luu();
        }
        private void LuuVaDong_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Luu();
            this.Close();
        }

        private void btnDong_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }

        private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            OnDeleteChange();
            this.Close();
        }

        void Luu()
        {
            if (_hinhThucHopDong.Oid == -1)
            {
                DataAccessObject.HinhThucHopDong.Insert(_hinhThucHopDong);
                OnSaveChange();

            }
            else
                DataAccessObject.HinhThucHopDong.Update(_hinhThucHopDong);
        }

        void OnSaveChange()
        {
            if (SaveChanged != null)
                SaveChanged(this, EventArgs.Empty);
        }
        void OnDeleteChange()
        {
            if (DeleteChanged != null)
                DeleteChanged(this, EventArgs.Empty);
        }
    }
}
